From: Brion Vibber
Date: Tue, 2 Mar 2004 09:26:57 +0000 (+0000)
Subject: Add database creation to in-place installer, plus a couple fixlets.
X-Git-Tag: 1.3.0beta1~882
X-Git-Url: http://git.cyclocoop.org/%28%5B%5E/404?a=commitdiff_plain;h=24bafe9227883b3347d9d7155b3f44fd96aeda69;p=lhc%2Fweb%2Fwiklou.git
Add database creation to in-place installer, plus a couple fixlets.
Installer is now able to connect to the db, check its version (and
enable some MySQL 4 features if available), create the database
if need be, create the empty tables, and grant user privs if given
the root pass. This creates a usable empty wiki.
TODO:
* Populate main page and stub log pages
* Create sysop account
* Populate MediaWiki namespace for selected language
* Better error checking
* Option for InnoDB tables?
* Other useful options like uploads and TeX (shudder)
* Support scripts still need to be checked for security.
Also fixed a minor bug in Database::tableExists which ran into infinite
loops if no tables were present, and made Database::selectDB modify
the right member variable.
To get around some problems induced by the new parser stuff, User
won't loadFromDatabase() if we're in CommandLineMode, since it ends
up trying to do so before we've set up the database and fails.
---
diff --git a/config/index.php b/config/index.php
index 99a18c73d9..d9d1959a9a 100644
--- a/config/index.php
+++ b/config/index.php
@@ -19,19 +19,21 @@
dl.setup dd {
}
- dl.setup dt {
- font-size: 0.8em;
- margin-left: 10em;
- margin-right: 200px;
- margin-bottom: 2em;
- }
dl.setup dd label {
+ clear: left;
font-weight: bold;
width: 10em;
float: left;
text-align: right;
padding-right: 1em;
}
+ dl.setup dt {
+ clear: left;
+ font-size: 0.8em;
+ margin-left: 10em;
+ /* margin-right: 200px; */
+ margin-bottom: 2em;
+ }
.error {
color: red;
}
@@ -150,11 +152,8 @@ print "Installation directory: " . htmlspecialchars( $conf->IP ) . "ScriptPath = preg_replace( '{^(.*)/config.*$}', '$1', $_SERVER["REQUEST_URI"] );
print "Script URI path: " . htmlspecialchars( $conf->ScriptPath ) . "\n";
-?>
-
-
-
-posted = ($_SERVER["REQUEST_METHOD"] == "POST");
+
$conf->Sitename = ucfirst( importPost( "Sitename", "" ) );
$conf->EmergencyContact = importPost( "EmergencyContact", $_SERVER["SERVER_ADMIN"] );
$conf->DBserver = importPost( "DBserver", "localhost" );
@@ -178,8 +177,133 @@ if( $conf->DBpassword != $conf->DBpassword2 ) {
$errs["DBpassword2"] = "Passwords don't match!";
}
+if( $conf->posted && ( 0 == count( $errs ) ) ) {
+ do { /* So we can 'continue' to end prematurely */
+ $conf->Root = ($conf->RootPW != "");
+
+ /* Load up the settings and get installin' */
+ $local = writeLocalSettings( $conf );
+ $wgCommandLineMode = false;
+ eval($local);
+
+ $wgDBadminuser = $wgDBuser;
+ $wgDBadminpassword = $wgDBpassword;
+ $wgCommandLineMode = true;
+ $wgUseDatabaseMessages = false; /* FIXME: For database failure */
+ include_once( "Setup.php" );
+
+ if( $conf->Root ) {
+ $wgDatabase = Database::newFromParams( $wgDBserver, "root", $conf->RootPW, "", 1 );
+ } else {
+ $wgDatabase = Database::newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, "", 1 );
+ }
+ $wgDatabase->mIgnoreErrors = true;
+
+ if ( !$wgDatabase->isOpen() ) {
+ $errs["DBserver"] = "Couldn't connect to database";
+ continue;
+ }
+
+ @$myver = mysql_get_server_info( $wgDatabase->mConn );
+ if( !$myver ) {
+ print "MySQL error " . ($err = mysql_errno() ) .
+ ": " . htmlspecialchars( mysql_error() );
+ switch( $err ) {
+ case 1045:
+ if( $conf->Root ) {
+ $errs["RootPW"] = "Check password";
+ } else {
+ $errs["DBuser"] = "Check name/pass";
+ $errs["DBpassword"] = "or enter root";
+ $errs["DBpassword2"] = "password below";
+ $errs["RootPW"] = "Got root?";
+ }
+ break;
+ case 2002:
+ case 2003:
+ $errs["DBserver"] = "Connection failed";
+ break;
+ default:
+ $errs["DBserver"] = "Couldn't connect to database";
+ }
+ continue;
+ }
+ print "Connected to database... $myver";
+ if( version_compare( $myver, "4.0.0" ) >= 0 ) {
+ print "; enabling MySQL 4 enhancements";
+ $conf->DBmysql4 = true;
+ $local = writeLocalSettings( $conf );
+ }
+ print "\n";
+
+ @$sel = mysql_select_db( $wgDBname, $wgDatabase->mConn );
+ if( $sel ) {
+ print "Database " . htmlspecialchars( $wgDBname ) . " exists\n";
+ } else {
+ $res = $wgDatabase->query( "CREATE DATABASE `$wgDBname`" );
+ if( !$res ) {
+ print "Couldn't create database " .
+ htmlspecialchars( $wgDBname ) .
+ "; try with root access or check your username/pass.\n";
+ $errs["RootPW"] = "<- Enter";
+ continue;
+ }
+ print "Created database " . htmlspecialchars( $wgDBname ) . "\n";
+ }
+
+ $wgDatabase->selectDB( $wgDBname );
+
+ if( $wgDatabase->tableExists( "cur" ) ) {
+ print "There are already MediaWiki tables in this database. Skipping rest of database setup...\n";
+ } else {
+ # FIXME: Check for errors
+ print "Creating tables...";
+ dbsource( "../maintenance/tables.sql", $wgDatabase );
+ dbsource( "../maintenance/interwiki.sql", $wgDatabase );
+ dbsource( "../maintenance/indexes.sql", $wgDatabase );
+ print " done.\n";
+
+ print "Initializing data...";
+ $wgDatabase->query( "INSERT INTO site_stats (ss_row_id,ss_total_views," .
+ "ss_total_edits,ss_good_articles) VALUES (1,0,0,0)" );
+
+ # FIXME: Initial sysop account
+ # FIXME: Main page, logs
+ # FIXME: Initialize messages
+ print "(NYI: accounts, pages, messages)\n";
+
+ if( $conf->Root ) {
+ # Grant user permissions
+ dbsource( "../maintenance/users.sql", $wgDatabase );
+ }
+ }
+
+ /* Write out the config file now that all is well */
+ print "Creating LocalSettings.php...
\n\n";
+ $f = fopen( "LocalSettings.php", "xt" );
+ if( $f == false ) {
+ dieout( "Couldn't write out LocalSettings.php. Check that the directory permissions are correct and that there isn't already a fiel of that name here." );
+ }
+ fwrite( $f, "<" . "?php\n$local\n?" . ">" );
+ fclose( $f );
+
+ print "Success! Move the LocalSettings.php file into the parent directory, then follow
+ this link to your wiki.
\n";
+
+ } while( false );
+}
+?>
+
+
+
+posted ) {
+ echo "Something's not quite right yet; make sure everything below is filled out correctly.
\n";
+ }
?>
Database config
@@ -281,29 +405,15 @@ if( count( $errs ) ) {
Creating LocalSettings.php...
\n\n";
-
- $local = writeLocalSettings( $conf );
- $f = fopen( "LocalSettings.php", "xt" );
- if( $f == false ) {
- dieout( "Couldn't write out LocalSettings.php. Check that the directory permissions are correct and that there isn't already a fiel of that name here." );
- }
- fwrite( $f, $local );
- fclose( $f );
-
- print "Success! Move the LocalSettings.php file into the parent directory, then follow
- this link to your wiki.
\n";
}
/* -------------------------------------------------------------------------------------- */
function writeAdminSettings( $conf ) {
- return "<" . "?php
+ return "
\$wgDBadminuser = \"{$conf->DBadminuser}\";
\$wgDBadminpassword = \"{$conf->DBadminpassword}\";
-?" . ">";
+";
}
function writeLocalSettings( $conf ) {
@@ -316,14 +426,14 @@ function writeLocalSettings( $conf ) {
$conf->LanguageCode = "en";
$conf->Encoding = "UTF-8";
}
- return "<" . "?php
+ return "
# This file was automatically generated. Don't touch unless you
# know what you're doing; see LocalSettings.sample for an edit-
# friendly file.
\$IP = \"{$conf->IP}\";
-ini_set( \"include_path\", ini_get(\"include_path\") . \":\$IP/includes:\$IP/languages\" );
-include_once( \"includes/DefaultSettings.php\" );
+ini_set( \"include_path\", \"\$IP/includes:\$IP/languages:\" . ini_get(\"include_path\") );
+include_once( \"DefaultSettings.php\" );
if( \$wgCommandLineMode ) {
die( \"Can't use command-line utils with in-place install yet, sorry.\" );
@@ -371,7 +481,7 @@ if( \$wgCommandLineMode ) {
\$wgLanguageCode = \"{$conf->LanguageCode}\";
" . ($conf->Encoding ? "\$wgInputEncoding = \$wgOutputEncoding = \"{$conf->Encoding}\";" : "" ) . "
-?" . ">";
+";
}
function dieout( $text ) {
@@ -398,10 +508,13 @@ function aField( &$conf, $field, $text, $type = "" ) {
}
function getLanguageList() {
- $wgLanguageCode = "xxx";
- function wfLocalUrl( $x ) { return $x; }
- function wfLocalUrlE( $x ) { return $x; }
- include( "../languages/Language.php" );
+ global $wgLanguageNames;
+ if( !isset( $wgLanguageNames ) ) {
+ $wgLanguageCode = "xxx";
+ function wfLocalUrl( $x ) { return $x; }
+ function wfLocalUrlE( $x ) { return $x; }
+ include( "../languages/Language.php" );
+ }
$codes = array();
$latin1 = array( "da", "de", "en", "es", "fr", "nl", "sv" );
@@ -423,4 +536,6 @@ function getLanguageList() {
}
?>
+
+